
#pragma once

#include "../common/read.h"

using namespace std;

inline bool dfs(int u,int tag, vector<int>&mch,vector<int>&vistime,vector<vector<int>>&e){
    if(vistime[u] == tag)//增广路径访问过之后不再访问
        return false;
    vistime[u] = tag;
    for (auto v : e[u])
        if((mch[v]==0)||dfs(mch[v],tag,mch,vistime,e)){
            mch[v] = u;
            return true;
        }
    return false;
}

int Hungarian_main(string fileName)
{
    int workerNum,taskNum,sumNum;
    // read(fileName,workerNum,taskNum,sumNum);
    read2(fileName,workerNum,taskNum,sumNum);

    vector<int> mch(sumNum,0), vistime(sumNum,0);
    vector<vector<int>> e(workerNum*taskNum);
    int ans=0;
    for (int i=0;i<workerNum;i++){
        for (int j=0;j<taskNum;j++){
            if(satisfyDistanceTime(workerLists[i],taskLists[j])){
                e[i+1].push_back(j+1);
            }
        }
    }
    
    for (int i=1; i<= workerNum; ++i)
        if(dfs(i,i,mch,vistime,e)){
            ans++;
        }
    return ans;
}
